/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.srcptit.trainning.giangnd.btvn2;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/**
 *
 * @author GIANG
 */
public class B9 {
    public static void main(String[] args) throws FileNotFoundException, IOException {
        BufferedReader br=new BufferedReader( new FileReader("Data/B9.txt"));
        BufferedWriter bf= new BufferedWriter(new FileWriter("Data/B9OUT.txt"));
        String s=null;
        s=br.readLine();
        System.out.println(s);
        int[] vt = new int[s.length()];
        int k = 1;
        for(int i=0;i<s.length();i++)
            if(s.charAt(i)==' ')
                vt[k++]=i;
        vt[0]=0;
        vt[k++]=s.length();
        int max=0,d=0,c=0;
        for(int i=0;i<k;i++)
            if((vt[i+1]-vt[i])>max){
                max=vt[i+1]-vt[i];
                d=vt[i];
                c=vt[i+1];
            }
        System.out.println("Tu dai nhat o vi tri :"+d);
        bf.write("Tu dai nhat trong cau o vi tri thu "+d);
        bf.newLine();
        for(int i=d+1;i<c;i++){
            System.out.print(s.charAt(i));
            bf.write(s.charAt(i));
        }
        bf.close();
    }
}
